<template>
  <div class="login">
    <div class="login-box">
      <img src="@/assets/login/login-l.png" alt="" />
      <div class="login-form">
        <el-form ref="loginForm" :v-model="loginForm" >
          <div class="login-form-title">
            <img
              src="@/assets/login/icon_logo.png"
              style="width: 149px; height: 38px"
              alt=""
            />
            <!-- <span class="title-label">苍穹外卖</span> -->
          </div>
          <el-form-item prop="username">

            <el-input
              v-model="loginForm.username"
              type="text"
              auto-complete="off"
              placeholder="账号"
               prefix-icon="el-icon-user"
            />
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              type="password"
              placeholder="密码"
              prefix-icon="el-icon-lock"
              @keyup.enter.native="handleLogin"
            />
          </el-form-item>
          <el-form-item style="width: 100%">
            <el-button
              :loading="loading"
              class="login-btn"
              size="medium"
              type="primary"
              style="width: 100%;
               border-radius: 17px;
               margin-top: 20px;
               margin-left: 20px;
                background-color:#ffc200;
               font-weight: 500;
               font-size: 15px;
               border: none;
               font-weight: 600;
                       color: #726e6e;"
              @click="handleLogin"

            >
              <span v-if="!loading">登录</span>
              <span v-else>登录中...</span>
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script >
import { checkLogin } from '@/api/login'
import { setuserName } from '@/utils/storage'
export default {
  name: 'loginIndex',

  data () {
    return {
      loginForm: {
        username: '',
        password: ''
      },
      loginRules: '',
      loading: false

    }
  },

  methods: {

    async handleLogin () {
      const res = await checkLogin(this.loginForm)

      if (res.data.code === 1) {
        this.$message.success('登录成功')
        // 写入token
        this.loading = true
        this.$store.commit('user/setUserInfo', res.data.data)
        // 保存用户名
        setuserName(this.loginForm.username)

        this.$router.push('/workbeach')
      }

    //
    }

  }

}
</script>

<style lang="less" secpod>

.login {
  /* display: flex; */
  justify-content: center;
  align-items: center;
  height: 100vh;
  // background: #476dbe;
  background-color: #333;

}

.login-box {

  /* width: 1380px; */
  width: 1380px;
  height: 95vh;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
  border-radius: 8px;
  display: flex;
  img {
    width: 60%;
    height: auto;
  }
}

.title {
  margin: 0px auto 10px auto;
  text-align: left;
  color: #707070;
}

.login-form {
  background: #ffffff;
  width: 40%;
  border-radius: 0px 8px 8px 0px;
  display: flex;
  justify-content: center;
  align-items: center;
  .el-form {
    width: 214px;
    height: 307px;
  }
  .el-form-item {
    margin-bottom: 30px;
  }
 /deep/ .el-form-item.is-error .el-input__inner {

    border: 0 !important;
    border-bottom: 1px solid #fd7065 !important;
    background: #fff !important;
  }
 /deep/  .el-input{
    padding-left: 30px;
  }
 /deep/  .el-input__inner {

    border: 0;
    border-bottom: 1px solid #e9e9e8;
    border-radius: 0;
    font-size: 12px;
    font-weight: 400;
    color: #333333;
    height: 32px;
    line-height: 32px;
  }
  /deep/ .el-input--prefix .el-input__inner {
    padding-left: 1px;
  }
  // 输入框选中的状态
 /deep/ .el-input__inner:focus {
  outline-color: rgba(211, 212, 205, 0.445);
  //border-color: #ffc200;
 // border: 1px solid #ccc;
}

}
/deep/ .el-input__icon.el-icon-user{
  font-size: 20px;
}
/deep/ .el-input__icon.el-icon-lock{
  font-size: 20px;
}

.login-form-title {
  height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 40px;
  .title-label {
    font-weight: 500;
    font-size: 20px;
    color: #333333;
    margin-left: 10px;
  }
}
.login-btn {

  &:hover,
  &:focus {
    // background: #09a57a;
    background-color: #ffc200;
    color: #ffffff;
  }
}
</style>
